package com.mach.platform.sprider.dev;

import java.io.IOException;

public class Test {

	public static void main(String[] args) throws IOException {
//		getTransducerVoltage();
//		test3line();
		//sanAll();
//		testEle();
//		testKnd();
		testKunHan();
	}

	public static void testKunHan() throws IOException {
//		TransducerPlKunHanDev dh =  new TransducerPlKunHanDev("192.168.3.91",8003,2,"14#变频器（PA2、PO2工艺24H）");
        TransducerPlKunHanDev dh =  new TransducerPlKunHanDev("192.168.3.91",8003,2,"14#变频器（PA2、PO2工艺24H）");
		for(int i = 1; i <= 1; ++i) {


			System.out.println(dh.getPl() );
		}
	}


	public static void testKnd() throws IOException {
		GerenalStatusDev dh =  new WaterDumpKNDDev("192.168.3.91",8000,4,1,"test");
		for(int i = 1; i <= 1; ++i) {

			Integer status = dh.getStatus();
//			byte[] result = dh.getDataRtu(0,1);
//			byte[] data = ByteUtil.subData(result,1,1);
//			data = ByteUtil.reverse2Byte(data);
//			data = ByteUtil.reverse(data);
//			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );

			System.out.println(status);
		}
	}

	public static void sanAll() throws IOException {

		for(int i = 1; i <= 100; ++i) {
			DataHelper dh =  new DataHelper("192.168.3.90",8001,i);
			byte[] result = dh.getDataRtu(0,1);
//			byte[] data = ByteUtil.subData(result,1,1);
//			data = ByteUtil.reverse2Byte(data);
//			data = ByteUtil.reverse(data);
//			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );
		}
	}

	public static void testEle() throws IOException {
		DataHelper dh =  new DataHelper("192.168.3.92",8001,30);


		for(int i = 0; i < 1; ++i) {
			byte[] result = dh.getDataRtu(40022,4);
			byte[] data = ByteUtil.subData(result,3,4);
//			data = ByteUtil.reverse2Byte(data);
			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );
		}
	}

	/*
	 * 变频器电表电压
	 */
	public static void getTransducerVoltage() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.92",8001,1);

		for(int i = 0; i < 10; ++i) {
			byte[] result = dh.getDataRtu(40000,1);
			byte[] data = ByteUtil.subData(result,1,1);
			data = ByteUtil.reverse2Byte(data);
//			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );
		}
	}
	
	/*
	 * 冰冻水回水温度
	 */
	public static void coolWarterBackTemp() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.21",502,1);
		
		for(int i = 0; i < 100; ++i) {
			byte[] result = dh.getDataTcp(40, 2);
			byte[] data = ByteUtil.subData(result,9,4);
			data = ByteUtil.reverse2Byte(data);
			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data));
		}
		

	}
	
	/*
	 * 冰冻水供水温度
	 */
	public static void coolWarterInTemp() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.21",502,1);
		
		for(int i = 0; i < 100; ++i) {
			byte[] result = dh.getDataTcp(4, 2);
			byte[] data = ByteUtil.subData(result,9,4);
			data = ByteUtil.reverse2Byte(data);
			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data));
		}
	}
	/*
	 * 压缩空气环境温度
	 */
	public static void getCpAirEnvTemp() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.90",8002,7);
		
		
		for(int i = 0; i < 100; ++i) {
			byte[] result = dh.getDataRtu(36,2);
			byte[] data = ByteUtil.subData(result,4,4);
			data = ByteUtil.reverse2Byte(data);
//			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );
		}
	}
	
	/*
	 * 压缩空气累计量
	 */
	public static void getCpAirSumFlow() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.90",8002,7);
		
		
		for(int i = 0; i < 100; ++i) {
			byte[] result = dh.getDataRtu(12,2);
			byte[] data = ByteUtil.subData(result,3,4);
			data = ByteUtil.reverse2Byte(data);
			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data) );
		}
	}
	public static void test3line() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.90",8001,3);

		byte[] result = dh.getDataRtu(6,2);
		for(int i = 0; i < 1; ++i) {

			byte[] data = ByteUtil.subData(result,4,4);
			data = ByteUtil.reverse2Byte(data);
//			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data)  + " i=" + i);
		}
	}

	public static void test2() throws IOException {
		DataHelper dh = new DataHelper("192.168.3.90",8002,7);
		
		byte[] result = dh.getDataRtu(12,6);
		for(int i = 0; i < 11; ++i) {
			
			byte[] data = ByteUtil.subData(result,3 + i,4);
			data = ByteUtil.reverse2Byte(data);
			data = ByteUtil.reverse(data);
			System.out.println(ByteUtil.getFloat(data) + " int=" + ByteUtil.getInt(data)  + " i=" + i);
		}
	}


}
